//
//  SISSAddTakeLookViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/13.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSAddTakeLookViewController.h"
#import "SISSTitleView.h"
#import "SISSDatePickerView.h"
#import "SISSUploadImageView.h"


@interface SISSAddTakeLookViewController ()<SISSChooseViewDelegate, SISSDatePickerViewDelegate,SISSUploadImageViewDelegate>

@property (weak, nonatomic) SISSTitleView *tipView;
@property (weak, nonatomic) SISSTitleView *photoView;
@property (weak, nonatomic) SISSChooseView *timeView;
@property (weak, nonatomic) SISSUploadImageView *uploadImageView;
@property (weak, nonatomic) UIButton *confirmButton;


/* date */
@property (strong, nonatomic) NSDate *date;

@end

@implementation SISSAddTakeLookViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"添加看房记录";
    self.date = [NSDate date];
    
}

- (void)setDateStr:(NSString *)dateStr {
    _dateStr = dateStr;
    self.timeView.rightStr = [dateStr substringToIndex:10];
}


/**
 确定按钮点击事件
 */
- (void)confirmButtonClickAction:(UIButton *)sender {
    
    if (!self.dateStr) {
        [SISSTools showSVTitle:@"请选择看房时间" andTime:1.0 andColor:YES];
        return;
    }
    
    self.confirmButton.enabled =NO;
    [self performSelector:@selector(changeButtonStatus) withObject:nil afterDelay:1.0f];//防止重复点击
}
-(void)changeButtonStatus {
    
    self.confirmButton.enabled = YES;
}

#pragma mark - SISSUploadImageViewDelegate
- (void)handlePhotoFinishedAction {
    self.images = self.uploadImageView.images;
}

#pragma mark - SISSDatePickerViewDelegate
- (void)determine:(SISSDatePickerView *)choose date:(NSDate *)date {

    NSString *timeStr = [choose stringFromDate:date];
    NSLog(@"determine  %@",timeStr);
    self.timeView.rightStr = timeStr;
    self.dateStr = timeStr;
    self.date = date;
}

- (void)changeTime:(SISSDatePickerView *)choose date:(NSDate *)date {
    
    NSString *timeStr = [choose stringFromDate:date];
    NSLog(@"changeTime  %@",timeStr);
}

#pragma mark - SISSChooseViewDelegate
- (void)clickChooseActionWithChooseView:(SISSChooseView *)chooseView {
    
    if (chooseView.tag == 100) { // 选择带看时间
        SISSDatePickerView *datePickerView = [[SISSDatePickerView alloc] initWithType:UIDatePickerModeDate title:@"看房时间"];
        [datePickerView setNowTime:self.date];
        [datePickerView setMaximumDate:[NSDate new]];
        datePickerView.delegate = self;
    } else { // 选择带看房源、客源
        
        [self chooseViewChooseAnction];
    }
}

- (void)chooseViewChooseAnction {
   
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    SISSTitleView *tipView = [[SISSTitleView alloc] init];
    tipView.titleStr = @"温馨提示：\n详细记载看房记录可有助于您进行跳单维权。";
    [self.view addSubview:tipView];
    self.tipView = tipView;
    
    SISSChooseView *timeView = [[SISSChooseView alloc] init];
    timeView.leftStr = @"*看房时间：";
    timeView.rightPlaceStr = @"请选择看房时间";
    timeView.rightStr = self.dateStr;
    timeView.tag = 100;
    timeView.delegate = self;
    timeView.isShowBottomLine = YES;
    [self.view addSubview:timeView];
    self.timeView = timeView;
    
    SISSChooseView *chooseView = [[SISSChooseView alloc] init];
    chooseView.leftStr = @"*客源信息";
    chooseView.rightPlaceStr = @"请选择客源信息";
    chooseView.tag = 101;
    chooseView.delegate = self;
    [self.view addSubview:chooseView];
    self.chooseView = chooseView;

    
    SISSTitleView *photoView = [[SISSTitleView alloc] init];
    photoView.titleStr = @"*看房照片（须体现对应房源及客源信息）";
    [self.view addSubview:photoView];
    self.photoView = photoView;
    
    // 图片选择
    SISSUploadImageView *uploadImageView = [[SISSUploadImageView alloc] init];
    uploadImageView.isHiddenTitle = YES;
    uploadImageView.delegate = self;
    [self.view addSubview:uploadImageView];
    self.uploadImageView = uploadImageView;
    
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [confirmButton setBackgroundColor:MAIN_COLOR];
    [confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(confirmButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:confirmButton];
    self.confirmButton = confirmButton;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    WeakSelf
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.top.equalTo(weakSelf.view).offset(kTopHeight);
        make.height.mas_equalTo(64);
    }];
    [self.timeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.top.equalTo(weakSelf.tipView.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    [self.chooseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.top.equalTo(weakSelf.timeView.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    [self.photoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.top.equalTo(weakSelf.chooseView.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    [self.uploadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.top.equalTo(weakSelf.photoView.mas_bottom);
        
    }];
    
    [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(44);
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.equalTo(weakSelf.view);
        }
    }];
}


@end
